define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	var wind_async = require('ddf_wind_async');

	var base = require('component-base');
	
	
	var myScrollTop=0;
	window.onscroll=function(){	
		function get_scrollTop_of_body(){ //scrollTop能力检测函数
					var scrollTop; 
					if(typeof window.pageYOffset != 'undefined'){ 
					scrollTop = window.pageYOffset; 
					} 
					else 
					if(typeof document.compatMode != 'undefined' && 
					document.compatMode != 'BackCompat'){ 
					scrollTop = document.documentElement.scrollTop; 
					} 
					else 
					if(typeof document.body != 'undefined'){ 
					scrollTop = document.body.scrollTop; 
					} 
					return scrollTop; 
		}
		 myScrollTop = parseInt(get_scrollTop_of_body());//获取ScrollTop的值
	}
	
	
	/**
	 * 商家类型列表
	 */
	exports.ddf_dialog_shop_type = function(id, fn) {

		$(id).ddf_dialog_tree({
			options : {
				type : "商家类型",
				url :ddf.shop.getErpShopTypeList,
				dialog_id : "shopTypeListDiv",
				dialog_List : "shopTypeList",
				page_id : "footPageShopTypeDiv",
				table_title : "商家类型列表",
				id_title : "类型代码",
				name_title : "类型名称",
				id_key : "SHOP_TYPE_ID",
				name_key : "SHOP_TYPE_NAME",
				search_text_array : [ "类型代码", "类型名称" ],
				search_key_array : [ "agentname", "contact" ],
				list_key : "shopTypeListData",
				confirmCallBack : fn
			}

		});
	};
	
	
	
	/**
	 * 商品单位列表
	 */
	exports.ddf_dialog_mer_unit = function(id, fn) {

		$(id).ddf_dialog({
			options : {
				type : "商品单位",
				url : ddf.merchandise.getDUnitsList,
				dialog_id : "merUnitListDiv",
				dialog_List : "merUnitList",
				page_id : "footPageMerUnitDiv",
				table_title : "商品单位列表",
				id_title : "单位代码",
				name_title : "单位名称",
				id_key : "unitCode",
				name_key : "unitName",
				search_text_array : [ "单位代码", "单位名称" ],
				search_key_array : [ "unitCode", "unitName" ],
				list_key : "dUnitsList",
				confirmCallBack : fn
			}

		});
	};
	
	/**
	 * 银行列表
	 */
	exports.ddf_dialog_bank = function(id, fn) {

		$(id).ddf_dialog({
			options : {
				type : "银行",
				url : ddf.bank.queryBankParamsList,
				dialog_id : "bankListDiv",
				dialog_List : "bankList",
				page_id : "footPageBankDiv",
				table_title : "银行列表",
				id_title : "银行代码",
				name_title : "银行名称",
				id_key : "bankId",
				name_key : "bankName",
				search_text_array : [ "银行代码", "银行名称" ],
				search_key_array : [ "bankId", "bankName" ],
				list_key : "banksListData",
				confirmCallBack : fn
			}

		});
	};
	

     /**
      * 用户列表
      */
	exports.ddf_dialog_user = function(id, fn) {

		$(id).ddf_dialog_userList({
			options : {
				type : "用户",
				url : ddf.staff.queryAllUser,
				dialog_id : "userListDiv",
				dialog_List : "userListDia",
				page_id : "footPageUserDiv",
				table_title : "用户列表",
				id_title : "用户代码",
				name_title : "用户名",
				mobile : "手机号码",
				realName : "真实姓名",
				email : "邮箱地址",
				id_key : "USER_ID",
				name_key : "USER_NAME",
				mobile_key : "MOBILE",
				realName_key : "REAL_NAME",
				email_key : "EMAIL",
				search_text_array : [ "用户代码", "用户名称" ],
				search_key_array : [ "user_id", "user_name" ],
				list_key : "userListData",
				confirmCallBack : fn
			}

		});
	};
	
	
	/**
	 * 会员列表
	 */
	exports.ddf_dialog_member = function(id, fn) {

		$(id).ddf_dialog_memberList({
			options : {
				type : "会员",
				url : ddf.member.getQueryMember,
				dialog_id : "memberListDiv",
				dialog_List : "memberList",
				page_id : "footPageMemberDiv",
				table_title : "会员列表",
				userId_title : "用户编码",
				name_title : "用户账号",
				mobile_title : "手机号码",
				realName_title : "真实姓名",
				userId_key : "USER_ID",
				userName_key : "USER_NAME",
				mobile_key : "MOBILE",
				realName_key : "REAL_NAME",
				search_text_array : [ "用户账号", "手机号码" ],
				search_key_array : [ "username", "mobile" ],
				list_key : "memberListData",
				confirmCallBack : fn
			}

		});
	};
	
	/**
     * 板块列表
     */
	exports.ddf_dialog_area = function(id,regionId, fn) {

		$(id).ddf_dialog({
			options : {
				type : "板块",
				url : ddf.house.getAreaList+'?regionId='+regionId,
				dialog_id : "areaListDiv",
				dialog_List : "areaListDia",
				page_id : "footPageUserDiv",
				table_title : "板块列表",
				id_title : "板块代码",
				name_title : "板块名称",
				id_key : "areaId",
				name_key : "name",
				search_text_array : [ "板块代码", "板块名称" ],
				search_key_array : [ "areaId", "name" ],
				list_key : "areaListData",
				confirmCallBack : fn
			}

		});
	};
	
	/**
     * 置业顾问列表
     */
	exports.ddf_dialog_cons = function(id,regionId, fn) {

		$(id).ddf_dialog_consList({
			options : {
				type : "置业顾问",
				url : ddf.house.getHouseConsList,
				dialog_id : "housConsListDiv",
				dialog_List : "housConsListDia",
				page_id : "footPageUserDiv",
				table_title : "置业顾问列表",
				id_title : "顾问代码",
				name_title : "顾问名称",
				mobile : "联系电话",
				id_key : "HCId",
				name_key : "name",
				mobile_key : "phone",
				search_text_array : [ "顾问代码", "顾问名称" ],
				search_key_array : [ "hCId", "name" ],
				list_key : "houseConsListData",
				confirmCallBack : fn
			}

		});
	};
	
	/**
	 * 生产厂家列表
	 */
	exports.ddf_dialog_vendor = function(id, type, fn) {
		
		$(id).ddf_dialog({
			options : {
				type : "生产厂家",
				searchType : type,
				url : ddf.vendor.getVendorList,
				dialog_id : "vendorListDiv",
				dialog_List : "vendorList",
				page_id : "footPageVendorDiv",
				table_title : "厂家列表",
				id_title : "厂家编码",
				name_title : "厂家名称",
				id_key : "VENDOR_ID",
				name_key : "VENDOR_NAME",
				get_id_key : "VENDOR_ID",
				search_text_array : [ "厂家编码", "厂家名称" ],
				search_key_array : [ "vendor_id", "vendor_name" ],
				list_key : "vendorListData",
				confirmCallBack : fn
			}

		});
	};
	
	
	

	$.fn.ddf_dialog = function(opts) {
//		alert("2");
		var panel = $(this);

		var params = {

			"page.pageNumber" : pageNumber,
			"page.pageSize" : pageSize,
			"type":opts.options.searchType
		};

		return this
				.each(function() {
					
					/**
					 * 搜索
					 */
					function search() {

						params[opts.options.search_key_array[0]] = $(
								"#dialog_" + opts.options.search_key_array[0])
								.val();
						params[opts.options.search_key_array[1]] = $(
								"#dialog_" + opts.options.search_key_array[1])
								.val();
						loadList();
					}

					/**
					 * 重置
					 */
					function resetParams() {

						$("#dialog_" + opts.options.search_key_array[0])
								.val("");
						$("#dialog_" + opts.options.search_key_array[1])
								.val("");
					}

					/**
					 * 查询列表
					 */
					function loadList() {

						base.showLoading();
						
						eval(
								Wind.compile("async", function() {

									var data = $await(wind_async
											.DDF_AsyncRequest("POST",
													opts.options.url, params));

									loadListCallBack(data);

								}))().start();

					}

					/**
					 * 回调函数
					 */
					function loadListCallBack(data) {
						if (data["code"] == 1) {
							$("#" + opts.options.dialog_List).html("");

							for (var i = 0; i < data[opts.options.list_key].length; i++) {
								
								var htmlStr = "";
								htmlStr += '<tr id="dialog_confirm' + i + '">';
								htmlStr += '<td class="center">'
										+ base.getSequence(data["pageNumber"],
												data["pageSize"], i + 1)
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.id_key]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.name_key]
										+ '</td>';
								htmlStr += '</tr> ';

								$("#" + opts.options.dialog_List).append(
										htmlStr);
                                 
								var id = data[opts.options.list_key][i][opts.options.id_key];

								var name = data[opts.options.list_key][i][opts.options.name_key];

								$("#dialog_confirm" + i).on(
										"click",
										function() {

											opts.options.confirmCallBack(
													$(this).find("td:eq(1)")
															.text(), $(this)
															.find("td:eq(2)")
															.text());

											$("#" + opts.options.dialog_id)
													.remove();

											$("body .big_modal-backdrop")
													.remove();

										});
							}

							// 分页
							$('#' + opts.options.page_id).ddf_pagination(
									data["pageSize"],
									data["pageNumber"],
									data["totalCount"],
									data["totalPage"],
									{

										changePageCallback : function(pageSize,
												page) {

											params["page.pageNumber"] = page;

											loadList();
										},
										changePageSizeCallBack : function(
												pageSize) {

											params["page.pageSize"] = pageSize;

											loadList();
										}
									});
						}

						base.cancelLoading();

					}

					/**
					 * 初始化页面元素
					 */
					function init() {

						var divcont = '<div class="big_modal" id="'
								+ opts.options.dialog_id
								+ '" style="margin-top:'+myScrollTop+'px">'
								+ '<div class="modal-header">'
								+ '<button class="close over" type="button">×</button>'
								+ '<h3>'
								+ opts.options.table_title
								+ '</h3>'
								+ '</div>'
								+ '<div>'
								+ '<div class="row-fluid">'
								+ '<div class="span12">'
								+ '<div class="widget-content nopadding">'
								+ '<form class="form-horizontal">'
								+ '<div class="row-fluid">'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[0]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[0]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[1]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[1]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="form-actions">'
								+ '<button class="btn btn-primary" id="searchBtn" type="button" >搜索</button>&nbsp;'
								+ '<button class="btn btn-info" id="resetBtn"  type="button">重置</button>&nbsp;'
								+ '<button class="btn btn-success" id="noBtn"  type="button">选择“无'+opts.options.type+'”</button>&nbsp;'
								+ '</div>'
								+ '</form>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="widget-content nopadding dataTables_wrapper">'
								+ '<table class="table table-bordered data-table">'
								+ '<colgroup>' + '<col width="100px" />'
								+ '</colgroup>' + '<thead>' + '<tr>'
								+ '<th>序号</th>' + '<th>'
								+ opts.options.id_title + '</th>' + '<th>'
								+ opts.options.name_title + '</th>'+'</tr>'
								+ '</thead>' + '<tbody id="'
								+ opts.options.dialog_List + '">' + '</tbody>'
								+ '</table>' + '<div id="'
								+ opts.options.page_id + '"></div>' + '</div>'
								+ '</div>' + '</div>'
								+ '<div class="big_modal-backdrop in"></div>';

						$(divcont).appendTo("body");

						$("#" + opts.options.dialog_id).find(".over").click(
								function() {
									$("#" + opts.options.dialog_id).remove();
									$("body .big_modal-backdrop").remove();
								});
						$("#searchBtn").click(function() {
							search();
						});
						$("#resetBtn").click(function() {
							resetParams();
						});
						$("#noBtn").click(function() {

							opts.options.confirmCallBack("", "");

							$("#" + opts.options.dialog_id).remove();

							$("body .big_modal-backdrop").remove();

						});
					}

					init();

					loadList();

				});
	};
	
	
	/**
	 * 会员列表，包含的字段包括（用户帐号，手机号码，真实姓名）
	 */
	 
    $.fn.ddf_dialog_memberList = function(opts) {
		
	var panel = $(this);

		var params = {
				"source" : "showNotInStaffMember",
				"page.pageNumber" : pageNumber,
				"page.pageSize" : pageSize
		};

		return this
				.each(function() {
				
					/**
					 * 搜索
					 */
					function search() {

						params[opts.options.search_key_array[0]] = $(
								"#dialog_" + opts.options.search_key_array[0])
								.val();
						params[opts.options.search_key_array[1]] = $(
								"#dialog_" + opts.options.search_key_array[1])
								.val();
						loadList();
					}

					/**
					 * 重置
					 */
					function resetParams() {

						$("#dialog_" + opts.options.search_key_array[0])
								.val("");
						$("#dialog_" + opts.options.search_key_array[1])
								.val("");
					}

					/**
					 * 查询列表
					 */
					function loadList() {

						base.showLoading();
						
						eval(
								Wind.compile("async", function() {

									var data = $await(wind_async
											.DDF_AsyncRequest("POST",
													opts.options.url, params));

									loadListCallBack(data);

								}))().start();

					}

					/**
					 * 回调函数
					 */
					function loadListCallBack(data) {
						if (data["code"] == 1) {
							$("#" + opts.options.dialog_List).html("");

							for (var i = 0; i < data[opts.options.list_key].length; i++) {
								
								var htmlStr = "";
								htmlStr += '<tr id="dialog_confirm' + i + '">';
							htmlStr += '<td class="center">'
										+ base.getSequence(data["pageNumber"],
												data["pageSize"], i + 1)
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.userId_key ]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.userName_key ]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.mobile_key ]
										+ '</td>';
								htmlStr += '<td>'
									+ data[opts.options.list_key][i][opts.options.realName_key ]
									+ '</td>';
								htmlStr += '</tr> ';

								$("#" + opts.options.dialog_List).append(
										htmlStr);
                                 
								var id = data[opts.options.list_key][i][opts.options.id_key];
								var name = data[opts.options.list_key][i][opts.options.name_key];

								$("#dialog_confirm" + i).on(
										"click",
										function() {

											opts.options.confirmCallBack(
													$(this).find("td:eq(1)")
															.text(), $(this)
														.find("td:eq(2)")
														.text(),$(this)
															.find("td:eq(3)")
															.text(),$(this)
														.find("td:eq(4)")
															.text());

											$("#" + opts.options.dialog_id)
													.remove();

											$("body .big_modal-backdrop")
													.remove();

										});
							}

							// 分页
							$('#' + opts.options.page_id).ddf_pagination(
									data["pageSize"],
									data["pageNumber"],
									data["totalCount"],
								data["totalPage"],
									{

									changePageCallback : function(pageSize,
											page) {

											params["page.pageNumber"] = page;

											loadList();
									},
									changePageSizeCallBack : function(
											pageSize) {

											params["page.pageSize"] = pageSize;

											loadList();
										}
									});
						}

						base.cancelLoading();

					}

					/**
					 * 初始化页面元素
					 */
					function init() {

						var divcont = '<div class="big_modal" id="'
								+ opts.options.dialog_id
								+ '" style="margin-top:'+myScrollTop+'px">'
								+ '<div class="modal-header">'
								+ '<button class="close over" type="button">×</button>'
								+ '<h3>'
								+ opts.options.table_title
								+ '</h3>'
								+ '</div>'
								+ '<div>'
								+ '<div class="row-fluid">'
								+ '<div class="span12">'
								+ '<div class="widget-content nopadding">'
								+ '<form class="form-horizontal">'
								+ '<div class="row-fluid">'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[0]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[0]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[1]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[1]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="form-actions">'
								+ '<button class="btn btn-primary" id="searchBtn" type="button" >搜索</button>&nbsp;'
								+ '<button class="btn btn-info" id="resetBtn"  type="button">重置</button>&nbsp;'
								+ '<button class="btn btn-success" id="noBtn"  type="button">选择“无'+opts.options.type+'”</button>&nbsp;'
								+ '</div>'
								+ '</form>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="widget-content nopadding dataTables_wrapper">'
								+ '<table class="table table-bordered data-table">'
								+ '<colgroup>' + '<col width="100px" />'
								+ '</colgroup>' + '<thead>' + '<tr>'
								+ '<th>序号</th>' + '<th>'
								+ opts.options.userId_title + '</th>' + '<th>'
								+ opts.options.name_title + '</th>' + '<th>'
								+ opts.options.mobile_title + '</th>' + '<th>'
								+ opts.options.realName_title + '</th>'+'<th>'
								+ '</thead>' + '<tbody id="'
								+ opts.options.dialog_List + '">' + '</tbody>'
								+ '</table>' + '<div id="'
								+ opts.options.page_id + '"></div>' + '</div>'
								+ '</div>' + '</div>'
								+ '<div class="big_modal-backdrop in"></div>';

						$(divcont).appendTo("body");

						$("#" + opts.options.dialog_id).find(".over").click(
								function() {
								$("#" + opts.options.dialog_id).remove();
									$("body .big_modal-backdrop").remove();
								});
						$("#searchBtn").click(function() {
							search();
						});
						
						$("#resetBtn").click(function() {
							resetParams();
						});
						
						$("#noBtn").click(function() {

							opts.options.confirmCallBack("", "");

							$("#" + opts.options.dialog_id).remove();

							$("body .big_modal-backdrop").remove();

						});
						
					}

					init();

					loadList();

				});
	};
	
	
	
	/**
	 * 用户列表，包含的字段包括（用户代码、用户名、手机号码、邮箱、地址）
	 */
	 
    $.fn.ddf_dialog_userList = function(opts) {
		
	var panel = $(this);

		var params = {

		"page.pageNumber" : pageNumber,
			"page.pageSize" : pageSize
		};

		return this
				.each(function() {
				
					/**
					 * 搜索
					 */
					function search() {

						params[opts.options.search_key_array[0]] = $(
								"#dialog_" + opts.options.search_key_array[0])
								.val();
						params[opts.options.search_key_array[1]] = $(
								"#dialog_" + opts.options.search_key_array[1])
								.val();
						loadList();
					}

					/**
					 * 重置
					 */
					function resetParams() {

						$("#dialog_" + opts.options.search_key_array[0])
								.val("");
						$("#dialog_" + opts.options.search_key_array[1])
								.val("");
					}

					/**
					 * 查询列表
					 */
					function loadList() {

						base.showLoading();
						
						eval(
								Wind.compile("async", function() {

									var data = $await(wind_async
											.DDF_AsyncRequest("POST",
													opts.options.url, params));

									loadListCallBack(data);

								}))().start();

					}

					/**
					 * 回调函数
					 */
					function loadListCallBack(data) {
						if (data["code"] == 1) {
							$("#" + opts.options.dialog_List).html("");

							for (var i = 0; i < data[opts.options.list_key].length; i++) {
								
								var htmlStr = "";
								htmlStr += '<tr id="dialog_confirm' + i + '">';
							htmlStr += '<td class="center">'
										+ base.getSequence(data["pageNumber"],
												data["pageSize"], i + 1)
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.id_key]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.name_key]
										+ '</td>';
								htmlStr += '<td>'
									+ data[opts.options.list_key][i][opts.options.mobile_key]
									+ '</td>';
								htmlStr += '<td>'
									+ data[opts.options.list_key][i][opts.options.realName_key]
									+ '</td>';
								htmlStr += '<td>'
									+ data[opts.options.list_key][i][opts.options.email_key]
									+ '</td>';
								htmlStr += '</tr> ';

								$("#" + opts.options.dialog_List).append(
										htmlStr);
                                 
								var id = data[opts.options.list_key][i][opts.options.id_key];
								var name = data[opts.options.list_key][i][opts.options.name_key];

								$("#dialog_confirm" + i).on(
										"click",
										function() {

											opts.options.confirmCallBack(
													$(this).find("td:eq(1)")
															.text(), $(this)
														.find("td:eq(2)")
														.text(),$(this)
															.find("td:eq(3)")
															.text(),$(this)
														.find("td:eq(4)")
															.text(),$(this)
															.find("td:eq(5)")
														.text());

											$("#" + opts.options.dialog_id)
													.remove();

											$("body .big_modal-backdrop")
													.remove();

										});
							}

							// 分页
							$('#' + opts.options.page_id).ddf_pagination(
									data["pageSize"],
									data["pageNumber"],
									data["totalCount"],
								data["totalPage"],
									{

									changePageCallback : function(pageSize,
											page) {

											params["page.pageNumber"] = page;

											loadList();
									},
									changePageSizeCallBack : function(
											pageSize) {

											params["page.pageSize"] = pageSize;

											loadList();
										}
									});
						}

						base.cancelLoading();

					}

					/**
					 * 初始化页面元素
					 */
					function init() {

						var divcont = '<div class="big_modal" id="'
								+ opts.options.dialog_id
								+ '" style="margin-top:'+myScrollTop+'px">'
								+ '<div class="modal-header">'
								+ '<button class="close over" type="button">×</button>'
								+ '<h3>'
								+ opts.options.table_title
								+ '</h3>'
								+ '</div>'
								+ '<div>'
								+ '<div class="row-fluid">'
								+ '<div class="span12">'
								+ '<div class="widget-content nopadding">'
								+ '<form class="form-horizontal">'
								+ '<div class="row-fluid">'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[0]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[0]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[1]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[1]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="form-actions">'
								+ '<button class="btn btn-primary" id="searchBtn" type="button" >搜索</button>&nbsp;'
								+ '<button class="btn btn-info" id="resetBtn"  type="button">重置</button>&nbsp;'
								+ '<button class="btn btn-success" id="noBtn"  type="button">选择“无'+opts.options.type+'”</button>&nbsp;'
								+ '</div>'
								+ '</form>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="widget-content nopadding dataTables_wrapper">'
								+ '<table class="table table-bordered data-table">'
								+ '<colgroup>' + '<col width="100px" />'
								+ '</colgroup>' + '<thead>' + '<tr>'
								+ '<th>序号</th>' + '<th>'
								+ opts.options.id_title + '</th>' + '<th>'
								+ opts.options.name_title + '</th>' + '<th>'
								+ opts.options.mobile + '</th>' + '<th>'
								+ opts.options.realName + '</th>'+'<th>'
								+ opts.options.email + '</th>'+'</tr>'
								+ '</thead>' + '<tbody id="'
								+ opts.options.dialog_List + '">' + '</tbody>'
								+ '</table>' + '<div id="'
								+ opts.options.page_id + '"></div>' + '</div>'
								+ '</div>' + '</div>'
								+ '<div class="big_modal-backdrop in"></div>';

						$(divcont).appendTo("body");

						$("#" + opts.options.dialog_id).find(".over").click(
								function() {
								$("#" + opts.options.dialog_id).remove();
									$("body .big_modal-backdrop").remove();
								});
						$("#searchBtn").click(function() {
							search();
						});
						
						$("#resetBtn").click(function() {
							resetParams();
						});
						
						$("#noBtn").click(function() {

							opts.options.confirmCallBack("", "");

							$("#" + opts.options.dialog_id).remove();

							$("body .big_modal-backdrop").remove();

						});
						
					}

					init();

					loadList();

				});
	};
	
	
	/**
	 * 置业顾问列表，包含的字段包括（顾问代码、名称、联系电话）
	 */
	 
    $.fn.ddf_dialog_consList = function(opts) {
		
	var panel = $(this);

		var params = {

		"page.pageNumber" : pageNumber,
			"page.pageSize" : pageSize
		};

		return this
				.each(function() {
				
					/**
					 * 搜索
					 */
					function search() {

						params[opts.options.search_key_array[0]] = $(
								"#dialog_" + opts.options.search_key_array[0])
								.val();
						params[opts.options.search_key_array[1]] = $(
								"#dialog_" + opts.options.search_key_array[1])
								.val();
						loadList();
					}

					/**
					 * 重置
					 */
					function resetParams() {

						$("#dialog_" + opts.options.search_key_array[0])
								.val("");
						$("#dialog_" + opts.options.search_key_array[1])
								.val("");
					}

					/**
					 * 查询列表
					 */
					function loadList() {

						base.showLoading();
						
						eval(
								Wind.compile("async", function() {

									var data = $await(wind_async
											.DDF_AsyncRequest("POST",
													opts.options.url, params));

									loadListCallBack(data);

								}))().start();

					}

					/**
					 * 回调函数
					 */
					function loadListCallBack(data) {
						if (data["code"] == 1) {
							$("#" + opts.options.dialog_List).html("");

							for (var i = 0; i < data[opts.options.list_key].length; i++) {
								
								var htmlStr = "";
								htmlStr += '<tr id="dialog_confirm' + i + '">';
							htmlStr += '<td class="center">'
										+ base.getSequence(data["pageNumber"],
												data["pageSize"], i + 1)
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.id_key]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.name_key]
										+ '</td>';
								htmlStr += '<td>'
									+ data[opts.options.list_key][i][opts.options.mobile_key]
									+ '</td>';
								htmlStr += '</tr> ';

								$("#" + opts.options.dialog_List).append(
										htmlStr);
                                 
								var id = data[opts.options.list_key][i][opts.options.id_key];
								var name = data[opts.options.list_key][i][opts.options.name_key];

								$("#dialog_confirm" + i).on(
										"click",
										function() {

											opts.options.confirmCallBack(
													$(this).find("td:eq(1)")
															.text(), $(this)
														.find("td:eq(2)")
														.text(),$(this)
															.find("td:eq(3)")
															.text());

											$("#" + opts.options.dialog_id)
													.remove();

											$("body .big_modal-backdrop")
													.remove();

										});
							}

							// 分页
							$('#' + opts.options.page_id).ddf_pagination(
									data["pageSize"],
									data["pageNumber"],
									data["totalCount"],
								data["totalPage"],
									{

									changePageCallback : function(pageSize,
											page) {

											params["page.pageNumber"] = page;

											loadList();
									},
									changePageSizeCallBack : function(
											pageSize) {

											params["page.pageSize"] = pageSize;

											loadList();
										}
									});
						}

						base.cancelLoading();

					}

					/**
					 * 初始化页面元素
					 */
					function init() {

						var divcont = '<div class="big_modal" id="'
								+ opts.options.dialog_id
								+ '" style="margin-top:'+myScrollTop+'px">'
								+ '<div class="modal-header">'
								+ '<button class="close over" type="button">×</button>'
								+ '<h3>'
								+ opts.options.table_title
								+ '</h3>'
								+ '</div>'
								+ '<div>'
								+ '<div class="row-fluid">'
								+ '<div class="span12">'
								+ '<div class="widget-content nopadding">'
								+ '<form class="form-horizontal">'
								+ '<div class="row-fluid">'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[0]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[0]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="span6">'
								+ '<div class="control-group">'
								+ '<label class="control-label">'
								+ opts.options.search_text_array[1]
								+ '：</label>'
								+ '<div class="controls">'
								+ '<input class="span8 m-wrap" type="text" id="dialog_'
								+ opts.options.search_key_array[1]
								+ '" />'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="form-actions">'
								+ '<button class="btn btn-primary" id="searchBtn" type="button" >搜索</button>&nbsp;'
								+ '<button class="btn btn-info" id="resetBtn"  type="button">重置</button>&nbsp;'
								+ '<button class="btn btn-success" id="noBtn"  type="button">选择“无'+opts.options.type+'”</button>&nbsp;'
								+ '</div>'
								+ '</form>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '<div class="widget-content nopadding dataTables_wrapper">'
								+ '<table class="table table-bordered data-table">'
								+ '<colgroup>' + '<col width="100px" />'
								+ '</colgroup>' + '<thead>' + '<tr>'
								+ '<th>序号</th>' + '<th>'
								+ opts.options.id_title + '</th>' + '<th>'
								+ opts.options.name_title + '</th>' + '<th>'
								+ opts.options.mobile + '</th>' + '</tr>'
								+ '</thead>' + '<tbody id="'
								+ opts.options.dialog_List + '">' + '</tbody>'
								+ '</table>' + '<div id="'
								+ opts.options.page_id + '"></div>' + '</div>'
								+ '</div>' + '</div>'
								+ '<div class="big_modal-backdrop in"></div>';

						$(divcont).appendTo("body");

						$("#" + opts.options.dialog_id).find(".over").click(
								function() {
								$("#" + opts.options.dialog_id).remove();
									$("body .big_modal-backdrop").remove();
								});
						$("#searchBtn").click(function() {
							search();
						});
						
						$("#resetBtn").click(function() {
							resetParams();
						});
						
						$("#noBtn").click(function() {

							opts.options.confirmCallBack("", "");

							$("#" + opts.options.dialog_id).remove();

							$("body .big_modal-backdrop").remove();

						});
						
					}

					init();

					loadList();

				});
	};
	
	//以树状显示
	$.fn.ddf_dialog_tree = function(opts) {
		var panel = $(this);

		return this
				.each(function() {


					/**
					 * 查询列表
					 */
					function loadList() {

						base.showLoading();
						
						setting = {	
								data: {
									simpleData: {
										enable: true,
										idKey:"id",		//主键标识
										pIdKey:"pid",	//父级ID标识
									}
								},
								async: {
									enable: true,
									url:opts.options.url,
									type:"post",
									dataFilter: filter	//异步提交回调函数
								},
								view: {
									selectedMulti: false//是否支持同级下多选
								},
						};

					}

					
					function filter(treeId, parentNode, childNodes) {
						var array = [];
						if (!childNodes) return null;
						for (var i=0, l=childNodes.shopTypeListData.length; i<l; i++) {
							repname = childNodes.shopTypeListData[i].SHOP_TYPE_NAME.replace(/\.n/g, '.');
							
							array[i] = {
									id:childNodes.shopTypeListData[i].SHOP_TYPE_ID,	//分类ID
									name:repname,												//分类名称
									pid:childNodes.shopTypeListData[i].PARENT_ID,			//父级分类ID
								};
							
						}
						base.cancelLoading();
						return array;
					}
					
					
					/**
					 * 回调函数
					 */
					function loadListCallBack(data) {
						if (data["code"] == 1) {

							$("#" + opts.options.dialog_List).html("");
							
							for (var i = 0; i < data[opts.options.list_key].length; i++) {
								var htmlStr = "";
								htmlStr += '<tr id="dialog_confirm' + i + '">';
								htmlStr += '<td class="center">'
										+ base.getSequence(data["pageNumber"],
												data["pageSize"], i + 1)
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.id_key]
										+ '</td>';
								htmlStr += '<td>'
										+ data[opts.options.list_key][i][opts.options.name_key]
										+ '</td>';
								htmlStr += '<td style="display:none">'
									+ data[opts.options.list_key][i][opts.options.get_id_key]
									+ '</td>';
								htmlStr += '<td style="display:none">'
									+ data[opts.options.list_key][i][opts.options.get_id_key2]
									+ '</td>';
								

								htmlStr += '</tr> ';

								$("#" + opts.options.dialog_List).append(
										htmlStr);

								var id = data[opts.options.list_key][i][opts.options.get_id_key];

								var name = data[opts.options.list_key][i][opts.options.name_key];
								
								$("#dialog_confirm" + i).on(
										"click",
										function() {

											opts.options.confirmCallBack(
													$(this).find("td:eq(3)")
															.text(), $(this)
															.find("td:eq(2)")
															.text(),$(this)
															.find("td:eq(4)")
															.text());

											$("#" + opts.options.dialog_id)
													.remove();

											$("body .big_modal-backdrop")
													.remove();

										});
							}

							// 分页
							$('#' + opts.options.page_id).ddf_pagination(
									data["pageSize"],
									data["pageNumber"],
									data["totalCount"],
									data["totalPage"],
									{

										changePageCallback : function(pageSize,
												page) {

											params["page.pageNumber"] = page;

											loadList();
										},
										changePageSizeCallBack : function(
												pageSize) {

											params["page.pageSize"] = pageSize;

											loadList();
										}
									});
						}

						base.cancelLoading();

					}

					function confirmSelect(){
						var treeObj = $.fn.zTree.getZTreeObj("merTypeTree");
						var nodes = treeObj.getSelectedNodes();
						if(nodes[0].level==0){
							alert("请选择二级的商家类型");
						}else{
						
							opts.options.confirmCallBack(nodes[0].id, nodes[0].name);
							$("#" + opts.options.dialog_id).remove();
							$("body .big_modal-backdrop").remove();
						}
					}
					
					/**
					 * 初始化页面元素
					 */
					function init() {
						var divcont = '<div class="big_modal" id="'
								+ opts.options.dialog_id
								+ '" style="margin-top:'+myScrollTop+'px">'
								+ '<div class="modal-header">'
								+ '<button class="close over" type="button">×</button>'
								+ '<h3>'
								+ opts.options.table_title
								+ '</h3>'
								+ '</div>'
								
								+ '<div class="widget-content"> '
								+ '<div id="merchandiseTypeZTree">'
								+ '<div class="content_wrap">'
								+ '<div class="zTreeDemoBackground left">'
								+ '<ul id="merTypeTree" class="ztree"></ul>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								+ '</div>'
								
								+ '<div class="modal-footer">'
								+ '<button id="noBtn" class="btn">选择“无'+opts.options.type+'”</button>'
								+ '<button id="confirmBtn" class="btn">确定</button>'
								+ '<button class="btn over">取消</button> </div>'
								   
								+ '</div>'
								+ '<div class="big_modal-backdrop in"></div>';

						$(divcont).appendTo("body");

						$("#" + opts.options.dialog_id).find(".over").click(
								function() {
									$("#" + opts.options.dialog_id).remove();
									$("body .big_modal-backdrop").remove();
								});
						
						$("#confirmBtn").click(function() {
							
							confirmSelect();
							
						});
						$("#noBtn").click(function() {

							opts.options.confirmCallBack("", "");

							$("#" + opts.options.dialog_id).remove();

							$("body .big_modal-backdrop").remove();

						});
						
						
					}

					init();

					loadList();

					$(document).ready(function(){
						$.fn.zTree.init($("#merTypeTree"), setting);
					}); 
				});
	}
});
